/*
 * DialogTerm.java
 *
 * Created on 15. únor 2008, 22:06
 */

package jgaf.automaton.pda;

import java.util.StringTokenizer;
import org.dom4j.DocumentException;

/**
 *
 * @author  hanis
 */
public class DialogTerm extends javax.swing.JDialog {
    
   // private PDASimulator parent;
    private PushdownAutomaton automata = null;
    
    public DialogTerm(java.awt.Frame parent) {
        super(parent, false);
    //    this.parent = (PDASimulator) parent;
        initComponents();
       // setDesign();
        this.setLocationRelativeTo(parent);        
    }
    
    public void setAutomata(PushdownAutomaton automata) {
        this.automata = automata;
    }
    
    
//    public void setDesign() {
//       // DesignManipulation.getInstance().setDesign(this.getContentPane());
//        this.validateTree();
//    }
    
    
//    public void addText(String text) {
//        area.setText(area.getText() + text + "\n");
//    }
    
    public void clearText() {
        area.setText("");
    }
    
    public void refreshMe() {
        area.setText(automata.getReport().createProcess());
    }
    
//    private void process(String text) {
//        StringTokenizer st = new StringTokenizer(text);
//        if(st.countTokens() > 0) {
//            String statement = st.nextToken();
//            if(statement.equals("design")) {
//                if(st.hasMoreTokens()) {
//                    String param = st.nextToken();
//                    try {                        
//                        XMLDataManipulation.getInstance().getDesign("data/design/" + param + ".xml");
//                        parent.setDesign();
//                        DesignManipulation.getInstance().setDesign(this.getContentPane());
//                    } catch (DocumentException ex) {
//                        addText("design " + param + " doesn't exist");
//                    }
//                } else {
//                    addText("statement design require parameter");
//                }
//            } else if(statement.equals("clear")) {
//                area.setText("");
//            } else if(statement.equals("exit")) {
//                setVisible(false);
//            } else if(statement.equals("write")) {
//                if(st.hasMoreTokens()) {
//                    String param = st.nextToken();
//                    if(param.equals("simulation")) {
//                        addText(automata.getReport());
//                    } else if(param.equals("automata")) {
//                        addText(automata.writeAutomataDetail());
//                    }else {
//                        addText("unknown parameter");
//                    }
//                } else {
//                    addText("statement write require parameter");
//                }
//                
//            } else {
//                addText("unknow statement");
//            }
//        } else {
//            addText("empty statement");
//        }
//            
//    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        area = new javax.swing.JTextArea();
        butBack = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(java.util.ResourceBundle.getBundle("pdasimulator/localization").getString("progress.title"));
        setAlwaysOnTop(true);
        area.setColumns(20);
        area.setEditable(false);
        area.setRows(5);
        jScrollPane1.setViewportView(area);

        butBack.setText(java.util.ResourceBundle.getBundle("pdasimulator/localization").getString("freq.back"));
        butBack.setMargin(new java.awt.Insets(1, 4, 1, 4));
        butBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butBackActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                    .add(butBack))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(butBack)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void butBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butBackActionPerformed
        setVisible(false);
    }//GEN-LAST:event_butBackActionPerformed
    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea area;
    private javax.swing.JButton butBack;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    
}
